from fastapi import APIRouter,Depends
from bson import ObjectId  # 需要导入 ObjectId 类型

from app.config.database import connect
from mongoengine import Document, StringField
from app.models.user import User
from app.api.auth import create_access_token, get_user,ACCESS_TOKEN_EXPIRE_MINUTES



router = APIRouter()

    
    
@router.get("/get_users/{user_id}")
async def read_user(user_id: str):
    user = User.objects(id=user_id).first()
    if user:
        return {"id": str(user.id), "name": user.name, "email": user.email}
    return {"message": "User not found"}


    
@router.post("/save/")
async def save():
    # 获取 users 集合
    # print(mongo_conn.users)

    user = User(nickname="John Doe", openid="01354354aweae")
    user.save()
    
    users_list = {}
    return {"users": users_list}
    
@router.put("/upda/")
async def upda():
    # 获取 users 集合
    # print(mongo_conn.users)

    user = User(nickname="John Doe", openid="01354354aweae")
    user.save()
    
    users_list = {}
    return {"users": users_list}
    
@router.delete("/del/")
async def delete():
    # 获取 users 集合
    # print(mongo_conn.users)

    user = User(nickname="John Doe", openid="01354354aweae")
    user.save()
    
    users_list = {}
    return {"users": users_list}    